﻿var usernameCheckProxy;

// Initializes global and proxy default variables.
function pageLoad() {
    // Instantiate the service proxy.
    usernameCheckProxy = new UsernameCheck.ValidateUsername();

    // Set the default call back functions.
    usernameCheckProxy.set_defaultSucceededCallback(SucceededCallback);
    usernameCheckProxy.set_defaultFailedCallback(FailedCallback);
}


// Processes the button click and calls
// the service Greetings method.  
function CheckUsername() {
    //The username to check.
    var username = document.getElementById("usernameInput").textContent;
    alert("Made it here! Checking username " + username);
    var greetings = usernameCheckProxy.Validate(username);
    alert(greetings);
}

// Callback function that
// processes the service return value.
function SucceededCallback(result) {
    var usernameElem = document.getElementById("usernameInput");
    if (result == false)
    {
        usernameElem.style = "background-color: red;";
    }
    else
    {
        usernameElem.style = "background-color: green;"
    }
}

// Callback function invoked when a call to 
// the  service methods fails.
function FailedCallback(error, userContext, methodName) {   
}

if (typeof (Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
